﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Antix.Data.Catalogue.Objects
{
    /// <summary>
    /// Database Schema Collection
    /// </summary>
    public class DatabaseSchemaCollection : DatabaseObjectCollection
    {
        #region Constructor

        /// <summary>
        /// Create collection
        /// </summary>
        internal DatabaseSchemaCollection(Database database)
        {
            Database = database;
        }

        #endregion

        #region Properties

        public Database Database { get; private set; }
        
        #region Indexers

        /// <summary>
        /// Get by key
        /// </summary>
        /// <param name="name">name</param>
        /// <returns></returns>
        new public DatabaseSchema this[string name]
        {
            get { return this[name, false]; }
        }

        /// <summary>
        /// Get by key
        /// </summary>
        /// <param name="name">name</param>
        /// <param name="create">Create a new one if not found</param>
        /// <returns></returns>
        public DatabaseSchema this[string name, bool create]
        {
            get
            {
                if (this.Contains(name)) { return (DatabaseSchema)base[name]; }
                else if (create) { return this.Add(name); }
                else { return null; }
            }
        }

        #endregion

        #endregion

        #region Methods

        #region Add

        /// <summary>
        /// Add new schema
        /// </summary>
        /// <param name="name">Name of the schema</param>
        /// <returns>New schema</returns>
        public DatabaseSchema Add(string name)
        {
            DatabaseSchema newItem = new DatabaseSchema(this.Database);
            newItem.Name = name;

            base.Add(newItem);

            return newItem;
        }

        /// <summary>
        /// Add Existing item to collection
        /// </summary>
        /// <param name="item"></param>
        internal void Add(DatabaseSchema item)
        {
            base.Add(item);
        }

        #endregion

        #endregion
    }
}
